#pragma once

#include "const.h"


class HttpConnection;

using HttpHandler = std::function< void(std::shared_ptr<HttpConnection>) >;

class LogicSystem : public Singleton<LogicSystem>
{
	friend class Singleton<LogicSystem>;
public:
	~LogicSystem() = default; 

	// 注册http的get请求
	void registerGet(std::string url, HttpHandler handler);
	// 注册http的post请求
	void registerPost(std::string url, HttpHandler handler);
	// 处理http的get请求
	bool handleGet(std::string path, std::shared_ptr<HttpConnection> con);
	// 处理http的post请求
	bool handlePost(std::string path, std::shared_ptr<HttpConnection> con);

	// 测试GET请求
	void handleGetTest(std::shared_ptr<HttpConnection> connection);
	// 处理Post请求的验证码
	void handlePostVerifyCode(std::shared_ptr<HttpConnection> connection);
	// 处理用户注册
	void handleUserRegister(std::shared_ptr<HttpConnection> connection);
	// 处理用户重置密码
	void handleResetPwd(std::shared_ptr<HttpConnection> connection);
	// 处理用户登录
	void handleUserLogin(std::shared_ptr<HttpConnection> connection);

private:
	LogicSystem();

private:
	std::map<std::string, HttpHandler> m_getHandlers;	// get请求与其对应回调函数的映射
	std::map<std::string, HttpHandler> m_postHandlers;	// post请求与其对应回调函数的映射
};

